package com.chijun.mform.create.dialog;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;

import com.chijun.mform.R;
import com.chijun.mform.create.adapter.SelectFormIconAdapter;
import com.chijun.mform.create.mode.FormIcon;
import com.example.ccj.b.c.dialog.DialogBase;
import com.example.ccj.b.c.recycler.BaseRecycler;
import com.example.ccj.u.ScreenUtils;
import com.example.ccj.u.SizeUtils;

import java.util.List;

/**
 * 展示字段类型列表dialog
 * 点击后返回
 */
public class SelectFormIconDialog extends DialogBase {

    List<FormIcon> iconList;
    ISelectFormIcon iSelectFormIcon;
    public SelectFormIconDialog(@NonNull Context context, List<FormIcon> iconList, ISelectFormIcon iSelectFormIcon) {
        super(context);
        this.iconList = iconList;
        this.iSelectFormIcon = iSelectFormIcon;
    }

    @Override
    public void onInit() {
        isCanClose(true);
        setLayout(R.layout.dialog_select_form_icon);
        setAlpha(1f);//透明度
        isCanClose(true);//点击允许关闭
        isShowBackground(false);//不显示背景
        setShowHeightRatio(true);//按比例显示
        setHeightRatio(0.5);//高度显示比例
        showInBottom();//底部弹出
        setFull(true);//是否铺满
        goneTitleLeftImage();

        int appScreenWidth = ScreenUtils.getAppScreenWidth();
        int dpWidth = SizeUtils.px2dp(appScreenWidth);
        int i = dpWidth / 60;

        BaseRecycler<FormIcon> fieldBaseRecycler = findViewById(R.id.dialog_select_form_icon_rec);
        fieldBaseRecycler.setLayoutManager(new GridLayoutManager(this.getContext(),i));

        fieldBaseRecycler.setAdapter(iconList,new SelectFormIconAdapter(iconList, new ISelectFormIcon() {
            @Override
            public void complete(FormIcon iconUrl) {
                if (iSelectFormIcon != null) iSelectFormIcon.complete(iconUrl);
                dismiss();
            }

            @Override
            public void cancel() {
                dismiss();
            }
        }));
    }

}
